#import "NSSegmentedControl+Additions.h"


@implementation NSSegmentedControl (BorkwareAdditions)

- (int) tagForSelectedSegment
{
    NSSegmentedCell *cell = [self cell];

    int selectedSegment = [cell selectedSegment];

    int tag = [cell tagForSegment: selectedSegment];

    return (tag);

} // tagForSelectedSegment


- (void) setTag: (int) tag  forSegment: (int) segment
{
    NSSegmentedCell *cell = [self cell];
    [cell setTag: tag  forSegment: segment];

} // setTag


- (int) tagForSegment: (int) segment
{
    NSSegmentedCell *cell = [self cell];

    int tag;
    tag = [cell tagForSegment: segment];

    return (tag);

} // tagForSegment


- (void) setTrackingMode: (NSSegmentSwitchTracking) trackingMode
{
    NSSegmentedCell *cell = [self cell];
    [cell setTrackingMode: trackingMode];

} // setTrackingMode


- (NSSegmentSwitchTracking) trackingMode
{
    NSSegmentedCell *cell = [self cell];

    NSSegmentSwitchTracking trackingMode;
    trackingMode = [cell trackingMode];

    return (trackingMode);

} // trackingMode


- (void) selectItemWithTag: (int) tag
{
    NSSegmentedCell *cell = [self cell];

    int i;
    for (i = 0; i < [cell segmentCount]; i++) {
        if ([cell tagForSegment: i] == tag) {
            [cell setSelectedSegment: i];
            break;
        }
    }

} // selectItemWithTag


- (void) setControlSize: (NSControlSize) size
{
    NSSegmentedCell *cell = [self cell];
    [cell setControlSize: size];

} // setControlSize


- (NSControlSize) controlSize
{
    NSSegmentedCell *cell = [self cell];
    NSControlSize size = [cell controlSize];

    return (size);

} // controlSize


// in radio mode, you can't unselect all segments if one is already
// selected
- (void) unselectAllSegments
{
    NSSegmentSwitchTracking current;
    current = [self trackingMode];

    [self setTrackingMode: NSSegmentSwitchTrackingMomentary];

    int i;
    for (i = 0; i < [self segmentCount]; i++) {
        [self setSelected: NO  forSegment: i];
    }

    [self setTrackingMode: current];

} // unselectAllSegments

@end // BorkwareAdditions


 
